<?php

namespace app\admin\model\superdata;

use think\Db;
use think\Model;
use app\admin\model\vactivities\Activity as vactivity;


class Activity extends Model
{

    

    

    // 表名
    protected $table = 'activity';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = false;

    // 定义时间戳字段名
    protected $createTime = false;
    protected $updateTime = false;
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'startTime_text',
        'isrecording_text',
        'status_text',
        'isticket_text',
     ];


    //获取状态字段
    public function getStatusList()
    {
        return ['0' => __('activity_status 0'),'1' => __('activity_status 1')];
    }
    public function getStatusTextAttr($value, $data)
    {
        $value = $value ? $value : $data['status'];
        $list = $this->getStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }
    public function getIsrecordingList()
    {
        return ['0' => __('Isrecording 0'), '1' => __('Isrecording 1')];
    }

    public function getIsticketList()
    {
        return ['0' => __('ticket_status 0'), '1' => __('ticket_status 1')];
    }

    //获取是否购买入场劵字段
    public function getIsticketTextAttr($value, $data)
    {
        $value = $value ? $value : $data['isticket'];
        $list = $this->getIsticketList();
        return isset($list[$value]) ? $list[$value] : '';
    }

    public function getStarttimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['startTime']) ? $data['startTime'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }


    public function getIsrecordingTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['isrecording']) ? $data['isrecording'] : '');
        $list = $this->getIsrecordingList();
        return isset($list[$value]) ? $list[$value] : '';
    }

    protected function setStarttimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }

    /*
     * 查找用户的发布活动数量
     */
    public static function getActCntByAdmId($uid){
            $count = Db::name("activity")->where('status',1)->where('admin_id',$uid)->count();
            if($count){
                return $count;
            }else{
                $count = 0;
                return $count;
            }


    }

}
